using QFramework;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;

namespace HareGame
{
    public class TipsManager : MonoBehaviour, ISingleton
    {
        [SerializeField]
        private Transform _transBg;

        [SerializeField]
        private Text _txtMsg;

        [SerializeField]
        private GameObject objPuchasing;

        private CanvasGroup _canvasGroup;

        /// <summary>
        /// 初始化
        /// </summary>
        public void OnSingletonInit()
        {
            _canvasGroup = GetComponent<CanvasGroup>();
            _canvasGroup.alpha = 0;
            objPuchasing.SetActive(false);
        }

        /// <summary>
        /// 定义单例
        /// </summary>
        public static TipsManager Instance
        {
            get { return MonoSingletonProperty<TipsManager>.Instance; }
        }

        public void ShowOrHidePuchasing(bool isShow)
        {
            objPuchasing.SetActive(isShow);
        }

        /// <summary>
        /// 显示Tips
        /// </summary>
        /// <param name="key">多语言Key</param>
        public void ShowTips(string key)
        {
            _txtMsg.text = GameEntry.Localization.GetValue(key);
            _transBg.DOKill();
            _canvasGroup.DOKill();
            _canvasGroup.alpha = 1;
            _transBg.localPosition = Vector3.zero;
            _transBg.localScale = Vector3.zero;
            _transBg.DOScale(1, 0.25f).SetEase(Ease.OutBack);
            _transBg.DOLocalMoveY(100, 0.5f).SetEase(Ease.Linear).SetDelay(0.75f);
            _canvasGroup.DOFade(0, 0.5f).SetEase(Ease.Linear).SetDelay(0.75f);
        }
    }
}